﻿using UnityEngine;
using System.Collections;

public class SelectUI : GameUI
{
    [HideInInspector]
    public GameObject m_pOwner = null;
    Color m_myColor = Color.clear;

    // Update is called once per frame
    void Update()
    {
        if (m_pOwner == null)
            Debug.Log("SelectUI's Owner is Null");

        m_myColor = transform.GetComponent<SpriteRenderer>().color;

        transform.position = m_pOwner.transform.position;

        if (m_pOwner.GetComponent<UnitStatus>().m_unitData.m_CurrentUnitState == BASEUNIT_STATE.IDLE
            || m_pOwner.GetComponent<UnitStatus>().m_unitData.m_CurrentUnitState == BASEUNIT_STATE.MOVE)
            m_myColor = new Color(1.0f, 1.0f, 1.0f, m_myColor.a);
        else if (m_pOwner.GetComponent<UnitStatus>().m_unitData.m_CurrentUnitState == BASEUNIT_STATE.KNOCKBACK
            || m_pOwner.GetComponent<UnitStatus>().m_unitData.m_CurrentUnitState == BASEUNIT_STATE.FEAR
            || m_pOwner.GetComponent<UnitStatus>().m_unitData.m_CurrentUnitState == BASEUNIT_STATE.RETREAT
            || m_pOwner.GetComponent<UnitStatus>().m_unitData.m_CurrentUnitState == BASEUNIT_STATE.RELOAD)
            m_myColor = new Color(0.69f, 0, 0, m_myColor.a);
        else if (m_pOwner.GetComponent<UnitStatus>().m_unitData.m_CurrentUnitState == BASEUNIT_STATE.AIM)
            m_myColor = new Color(0.83f, 0.82f, 0, m_myColor.a);
        else if (m_pOwner.GetComponent<UnitStatus>().m_unitData.m_CurrentUnitState == BASEUNIT_STATE.COVER)
            m_myColor = new Color(0, 0.81f, 0.54f, m_myColor.a);

        transform.GetComponent<SpriteRenderer>().color = m_myColor;

        transform.GetChild(0).GetComponent<SpriteRenderer>().color = transform.GetComponent<SpriteRenderer>().color;
    }
}
